<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
?>

<html>

    <table border='1'>
        <tr>
          <th>Date of Test</th>
          <th>Temperature</th>
          <th>Alkalinity</th>
          <th>PH</th>
          <th>Ammonia</th>
          <th>Nitrate</th>
          <th>P04</th>
          <th>ORP</th>
          <th>Calcium</th>
          <th>Magnesium</th>
          <th>Salinity</th>
          <th>SG</th>
        </tr>
<?php
    
   //Manual SQL Connection
   $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error()); 
   
   mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());
   

    //SQL Query to view tests
    $result = mysql_query("select test_date,temp,dkh,ph,amon,nitrate,po4,orp,cal,mag,salinity from water_tests where user_id='". $_SESSION['uid'] ."'");
    
    //Fetches the table results to display for user
    while ($row = mysql_fetch_array($result)): ?>
      
      <td><?php echo $row['test_date']; ?></td>
      <td><?php echo $row['temp']; ?></td>
      <td><?php echo $row['dkh']; ?></td>
      <td><?php echo $row['ph']; ?></td>
      <td><?php echo $row['amon']; ?> </td>
      <td><?php echo $row['nitrate']; ?></td>
      <td><?php echo $row['po4']; ?></td>
      <td><?php echo $row['orp']; ?></td>
      <td><?php echo $row['cal']; ?></td>
      <td><?php echo $row['mag']; ?></td>
      <td><?php echo $row['salinity']; ?></td>
      <td><?php echo $row['sg']; ?></td>
      <!--Offers edit and delete functionality-->
      <td><?php echo '<a href="edittest.php?action=edit&test_date=' . $row['test_date'] .' ">[EDIT]</a>';?></td>
      <td><?php echo '<a href="deletetest.php?type=test&test_date=' . $row['test_date'] .' ">[DELETE]</a>';?></td>    
      
    </td>
    </tr>
    <?php
    endwhile;
    mysql_close($con);
    ?>
  </table>
    </br>
    <a href="http:./../WelcomePage/WelcomePage.php">Home Page</a>
</html>